// Promise.race() 返回最先完成的 Promise
const promises = [
    new Promise(resolve => setTimeout(() => resolve('快'), 100)),
    new Promise(resolve => setTimeout(() => resolve('慢'), 1000))
];

Promise.race(promises)
    .then(result => {
        console.log(result); // '快'
    });

// 应用场景：超时控制
const timeout = new Promise((_, reject) =>
    setTimeout(() => reject('超时'), 5000)
);

Promise.race([fetch('/api'), timeout])
    .then(response => console.log('请求成功'))
    .catch(error => console.log('请求超时'));